package com.example.smart_city_0829.activity.pet_hos;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.base.CommonAdapter;
import com.example.smart_city_0829.entity.petHos.PetDoc;
import com.example.smart_city_0829.retrofit.NetCallBack;
import com.example.smart_city_0829.utils.Constant;
import com.example.smart_city_0829.view.MaxSizeLv;

import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

public class FindDoctorActivity extends BaseActivity {

    private MaxSizeLv lv;

    private int pageNum = 1;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_find_doctor;
    }

    @Override
    protected void initView() {
        lv = (MaxSizeLv) findViewById(R.id.lv);

    }

    @Override
    protected void initData() {
        api.getDoctorList(Constant.pageSize,pageNum).enqueue(new NetCallBack<PetDoc>() {
            @Override
            public void onResponse(Call<PetDoc> call, Response<PetDoc> response) {
                if (response.body() == null) return;

                final List<PetDoc.RowsBean> rows = response.body().getRows();
                lv.setAdapter(new LvAdapter(rows,context));
            }
        });
    }

    @Override
    protected void initEvent() {
        lv.setOnItemClickListener((parent, view, position, id) -> {
            final PetDoc.RowsBean item = (PetDoc.RowsBean) parent.getAdapter().getItem(position);

            final Intent intent = new Intent(context, InterrogationActivity.class);
            intent.putExtra("doc",gson.toJson(item));
            startActivity(intent);
        });
    }

    @Override
    protected String getActionBarTitle() {
        return "找医生";
    }

    static class LvAdapter extends CommonAdapter<PetDoc.RowsBean,CommonAdapter.CommListViewHolder>{

        public LvAdapter(List<PetDoc.RowsBean> data, Context context) {
            super(data, context);
        }

        @Override
        protected void setData(PetDoc.RowsBean data, int position, CommListViewHolder viewHolder, View convertView, Context context) {
            //TODO:
            Glide.with(context)
                    .load(Constant.BASE_URL + data.getAvatar())
                    .into(viewHolder.im);

            viewHolder.title.setText("医生姓名："+data.getName());
            viewHolder.content.setText(data.getGoodAt());
            viewHolder.tag1.setText("职称："+data.getJobName()+"/n职业编号："+data.getPracticeNo());
            viewHolder.tag2.setText("从业年限："+data.getWorkingYears());
        }

        @Override
        protected CommListViewHolder getViewHolder() {
            return new CommListViewHolder();
        }

        @Override
        protected void initView(CommListViewHolder viewHolder, View convertView) {
            viewHolder.im = (ImageView) convertView.findViewById(R.id.im);
            viewHolder.title = (TextView) convertView.findViewById(R.id.title);
            viewHolder.content = (TextView) convertView.findViewById(R.id.content);
            viewHolder.tag1 = (TextView) convertView.findViewById(R.id.tag1);
            viewHolder.tag2 = (TextView) convertView.findViewById(R.id.tag2);
            viewHolder.tag3 = (TextView) convertView.findViewById(R.id.tag3);

        }

        @Override
        protected int getItemLayoutResourceId() {
            return R.layout.common_list_item2;
        }
    }
}